/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.fei.ClassDiagram.Editor.Wrappers;

import java.util.Set;
import javax.lang.model.element.Modifier;
import org.netbeans.modules.classfile.Access;
import org.netbeans.modules.classfile.Field;

/**
 * Trieda ktora zovseobecnuje spolocne vlastnotsti
 * 
 * @author Tomas
 */
public class BasicClassMemberWrapper extends BasicClassElementWrapper {
    
    protected boolean staticMember;
    protected boolean abstractMod;
    protected int access;
    protected String typeSignature;
    protected String descriptor;
    
    public BasicClassMemberWrapper(Field field)
    {
        super(field);
        
        this.staticMember = field.isStatic();
        this.access = field.getAccess();
        this.typeSignature = field.getTypeSignature();
        this.descriptor = field.getDescriptor();
        this.abstractMod = false;
    }
    
    public BasicClassMemberWrapper(String name, String type, Set<Modifier> mods) {
        super(name, type);
        this.setByModifiers(mods);
        
        typeSignature = new String();
        descriptor = new String();
    }
    
    public boolean isStatic() {
        return this.staticMember;
    }
    
    public String getTypeSignature() {
        return this.typeSignature;
    }
    
    public void setByModifiers(Set<Modifier> mods) {
        this.abstractMod = mods.contains(Modifier.ABSTRACT);
        this.staticMember = mods.contains(Modifier.STATIC);
        
        if (mods.contains(Modifier.PRIVATE)) {
            this.access = Access.PRIVATE;
            return;
        }
        if (mods.contains(Modifier.PROTECTED)) {
            this.access = Access.PROTECTED;
            return;
        }
        if (mods.contains(Modifier.PUBLIC)); {
            this.access = Access.PUBLIC;
            return;
        }   
    }
    
    public String accessToString() {
            
        if (Access.isPublic(access))
            return "+";
        if (Access.isPrivate(access))
            return "-";
        if (Access.isProtected(access))
            return "#";
                
        //package private
        return "  ";
    }
    
    public String accessToFullString() {
        
        if (Access.isPublic(access))
            return "public";
        if (Access.isPrivate(access))
            return "private";
        if (Access.isProtected(access))
            return "protected";
                
        //package private
        return "package";
    }

    public String getDescriptor() {
        return descriptor;
    }
}
